﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Medianamik.Service.ActiveDirectory.Configuration;
using Medianamik.Service.ActiveDirectory.Service;
using StructureMap;
using StructureMap.Configuration.DSL;

namespace Medianamik.Service.ActiveDirectory.Registratrion
{
    public class ServiceRegistry : Registry
    {
        public ServiceRegistry()
        {
            ForRequestedType<IMembershipService>()
               .TheDefaultIsConcreteType<MembershipService>();

            ForRequestedType<IActiveDirectoryConfigService>()
                .TheDefaultIsConcreteType<ActiveDirectoryConfigService>()
                .EnrichWith((context, x) => ((ActiveDirectoryConfigService)x).GetInstance());

            ForRequestedType<IDomainService>()
                .TheDefault.Is.ConstructedBy(context =>
                {
                    var config = new Container(new ServiceRegistry()).GetInstance<IActiveDirectoryConfigService>(); //  ObjectFactory.GetInstance<IActiveDirectoryConfigService>();
                    return new LDAPDomainService(config.ServerName,
                                                 config.DomainUsername,
                                                 config.DomainPassword);
                });
        }
    }
}
